// --------------------------------------------------------------------------------------------------------------------
// <copyright file="MessageBoxExtensions.cs" company="Roman '4ux-nbIx' Novitsky">
//   Copyright (c) Roman '4ux-nbIx' Novitsky 2009
// </copyright>
// <summary>
//   Defines the MessageBoxExtensions type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace SettingsManager
{
  using System;
  using System.Text;

  using JetBrains.Util;


  /// <summary>
  /// Defines <see cref="MessageBox"/> class extension methods.
  /// </summary>
  internal static class MessageBoxExtensions
  {
    /// <summary>
    /// Shows the error.
    /// </summary>
    /// <param name="exception">The exception.</param>
    /// <param name="caption">The caption.</param>
    /// <param name="message">The message.</param>
    public static void ShowError(Exception exception, string caption, string message)
    {
      var stringBuilder = new StringBuilder();
      stringBuilder.AppendLine(message);

      while (exception != null)
      {
        stringBuilder.AppendLine();
        stringBuilder.AppendLine(exception.Message);
        stringBuilder.AppendLine();
        stringBuilder.AppendLine("Stack trace:");
        stringBuilder.AppendLine(exception.StackTrace);

        exception = exception.InnerException;
      }

      MessageBox.ShowError(stringBuilder.ToString(), caption);
    }
  }
}